<template>
	<view>
		<uni-card v-for="(item, index) in adviceList" :key="index" :title="item.title" :extra="item.extra"
			@click="navigateToDetail(item.id)">
			<text class="uni-body">{{ item.content }}</text>
		</uni-card>
		<image src="../../../static/yijian.png" class="floating-image" @click="navigateToEdit" />
	</view>
</template>

<script>
	import config from '@/config';
	export default {
		data() {
			return {
				adviceList: [],
				token:'',
				userInfo:[]
			}
		},
		created() {
			this.getList(); // 在组件创建时获取卡片数据
			this.getConfig();
		},
		methods: {
			getConfig() {
				
				const token = uni.getStorageSync('Token');
				console.log(token)
				const userInfo = uni.getStorageSync('UserInfo');
				console.log(userInfo)
			},
			getList() {
				uni.request({
					url: 'http://localhost:9207/advice/list', // 请求的 URL
					method: 'GET', // 请求方法
					data: {
					}, 
					header: {
						'authorization': 'Bearer ' + this.token
					},
					success: (res) => {
						console.log('请求成功:', res.data.rows);
						this.adviceList = res.data.rows
					},
					fail: (err) => {
						console.error('请求失败:', err);
					}
				});
			},
			navigateToDetail() {
				uni.navigateTo({
					url: '/pages/my/myAdvice/adviceDetail/adviceDetail'
				})
			},
			navigateToEdit() {
				uni.navigateTo({
					url: '/pages/my/myAdvice/editAdvice/editAdvice'
				})
			}
		}
	}
</script>

<style>
	.floating-image {
		position: fixed;
		right: 20px;
		bottom: 100px;
		width: 50px;
		height: 50px;

	}
</style>